// export function getWeeksForYear(year) {
//   const firstDayOfYear = new Date(year, 0, 1) // 1月1日
//   const lastDayOfYear = new Date(year, 11, 31) // 12月31日
//
//   const weeks = []
//   let currentWeek = [firstDayOfYear]
//
//   const currentDay = new Date(firstDayOfYear)
//
//   while (currentDay <= lastDayOfYear) {
//     if (currentDay.getDay() === 0) {
//       // 每周开始时，将当前周添加到weeks数组中
//       weeks.push(currentWeek)
//       currentWeek = [new Date(currentDay)] // 开始新的一周
//     } else {
//       currentWeek.push(new Date(currentDay)) // 将当前日期添加到当前周中
//     }
//
//     // 增加一天
//     currentDay.setDate(currentDay.getDate() + 1)
//   }
//
//   // 将最后一个周添加到weeks数组中
//   weeks.push(currentWeek)
//
//   return weeks.map((dates) => {
//     dates = dates.map((v) => {
//       const now = new Date()
//       const currentDate = new Date(
//         now.getFullYear(),
//         now.getMonth(),
//         now.getDate()
//       ).getTime()
//       const date = new Date(v)
//       const isCurrentDay = date.getTime() === currentDate
//       return {
//         timeStamp: date.getTime(),
//         day: date.getDay(),
//         date,
//         isCurrentDay,
//         year: date.getFullYear(),
//         month: date.getMonth() + 1,
//         dayStr: date.toLocaleDateString().replace(/\//g, '-'),
//       }
//     });
//     return dates
//   });
// }
import { chunk } from 'lodash';
import dayjs from "dayjs";

export function getWeeksForYear(year) {
  const dates = getDatesInYear(year);
  const weeks = chunk(dates, 7);
  return weeks.map((dates) => {
    dates = dates.map((v) => {
      const now = new Date();
      const currentDate = new Date(
        now.getFullYear(),
        now.getMonth(),
        now.getDate()
      ).getTime();
      const date = new Date(v);
      const isCurrentDay = date.getTime() === currentDate;
      return {
        timeStamp: date.getTime(),
        day: date.getDate(),
        date,
        isPreDay: date.getTime() < currentDate,
        isCurrentDay,
        year: date.getFullYear(),
        month: date.getMonth() + 1,
        dayStr: dayjs(date).format('YYYY-MM-DD'),
      };
    });
    return dates;
  });
}

function getDatesInYear(year) {
  const dates = [];
  let currentDate = new Date(year, 0, 1); // 1月1日
  let nextDate;

  while (currentDate.getFullYear() === year) {
    dates.push(currentDate);
    nextDate = new Date(currentDate.getTime() + 86400000); // 下一天的日期
    currentDate = nextDate;
  }

  return dates;
}
